import { userListPage,userDelete,userRemoves,userListId} from "@/api/user"
const user = {
  state: {
    data:{},
    delete:null,//获取到删除掉的数据
    removes:null,//获取到移除多条的的数据
    listId:null//获取某个id的数据
  },

  mutations: {
    //修改状态全部数据
    UserList:(state,data)=>{
      state.data=data;
    },
    //返回删除的数据
    UserDelete:(state,data)=>{
      state.delete=data
    },
    //返回移除多条数据
    UserRemoves:(state,data)=>{
      state.removes=data
    },
    //返回id的数据
    UserListId:(state,data)=>{
      state.listId=data
    }
  },

  actions: {
    // 页码约束的所有用户数据
    UserList({commit},playload) {
      return new Promise((resolve, reject) => {
        userListPage(playload).then(response => {
          commit("UserList",response);
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    //删除用户单条数据
    UserDelete({commit},id){
      return new Promise((resolve,reject)=>{
        userDelete(id).then(response=>{
          commit("UserDelete",response)
          resolve(response)
        }).catch(error=>{
          reject(error)
        })
      })
    },
    //移除用户多条数据
    UserRemoves({commit},selectionArray){
      return new Promise((resolve,reject)=>{
        userRemoves(selectionArray).then(response=>{
          commit("UserRemoves",response)
          resolve(response)
        }).catch(error=>{
          reject(error)
        })
      })
    },
    //通过id返回数据
    UserListId({commit},id){
      return new Promise((resolve,reject)=>{
        userListId(id).then(response=>{
          // console.log(response);
          commit("UserListId",response)
          resolve(response)
        }).catch(error=>{
          reject(error)
        })
      })
    }
  }

}

export default user;
